#include "networkview.h"
#include "ui_networkview.h"

#include "../viewmodelmanager.h"

NetworkView::NetworkView(QWidget *parent) :
    BaseView(parent),
    ui(new Ui::NetworkView)
{
    ui->setupUi(this);
    init();
}

void NetworkView::init()
{
    ui->currentViewLab->setText("NetworkTool");
    connect(ui->addClientBtn,&QPushButton::clicked,this,&NetworkView::onAddClientBtnClicked);
    connect(ui->addServerBtn,&QPushButton::clicked,this,&NetworkView::onAddServerBtnClicked);
}

//void NetworkView::showView()
//{
//    this->show();
//}

//void NetworkView::hideView()
//{
//    this->hide();
//}

NetworkView::~NetworkView()
{
    delete ui;
}

void NetworkView::update(QSharedPointer<Data> dataPtr)
{

}

void NetworkView::closeEvent(QCloseEvent *e)
{
    ViewModelManager::instance().update("MainViewModel");
    QWidget::closeEvent(e);
}

void NetworkView::onAddClientBtnClicked()
{
    ClientView* client = new ClientView;
    client->addObserver(this);
    ui->clientTabWidget->addTab(client,"client");
}

void NetworkView::onAddServerBtnClicked()
{
    ServerView* server = new ServerView;
    ui->serverTabWidget->addTab(server,"server");
}

